<?php
// quickLink
# writes out page links
function quickLink ($linkHref, $desc, $accessKey, $linkTitle) {

   $theLink = '<a href="'. SITE_URL."/".$linkHref .'" title="'. $desc .'" accesskey="'.
                   $accessKey .'">'. $linkTitle .'</a>';
   return $theLink;

}
// google_like_pagination.php
function pagination($number, $show, $showing, $firstlink, $baselink, $total_records="", $directory) {

	$disp = floor($show / 2);
    if ( $showing <= $disp) :

        //if ( ($disp - $showing) > 0 ):
        //$low  = ($disp - $showing);
        //else:
        $low = 1;
       // endif;
        $high = ($low + $show) - 1;

    elseif ( ($showing + $disp) > $number) :

        $high = $number;
        $low = ($number - $show) + 1;

    else:

        $low  = ($showing - $disp);
        $high = ($showing + $disp);

    endif;

    // next / prev / first / last
    if ( ($showing - 1) > 0 ) :
        if ( ($showing - 1) == 1 ):
        $prev  = quickLink ($directory."/".($showing - 1)."/".$firstlink, 'Previous', '', "Previous" );/*<img src='". SITE_URL . "/templates/" .TEMPLATEDIR . "/images/icons/resultset_previous.png'/>*/
        else:
        $prev  = quickLink ($directory."/".($showing - 1)."/".$baselink,
        'Previous', 'z', "Previous");/*<img src='". SITE_URL . "/templates/" .TEMPLATEDIR . "/images/icons/resultset_previous.png' />*/
        endif;
    else:
        $prev  = '';
    endif;

    $next  = ($showing + 1) <= $number ?
    quickLink ($directory."/".($showing + 1)."/".$baselink, 'Next', 'x', "Next") : '';/*<img src='". SITE_URL . "/templates/" .TEMPLATEDIR . "/images/icons/resultset_next.png' />*/

    if ( $prev == '')
    	$first = '';
    else
    	$first = quickLink ($directory."/"."1/".$firstlink, 'First Page', '', "First");/*<img src='". SITE_URL . "/templates/" .TEMPLATEDIR . "/images/icons/resultset_first.png' />*/

    if ( $showing == $number ):
    $last = '';
    else:
    $last = quickLink ($directory."/".$number."/".$baselink, 'Last Page', '', "Last");/*<img src='". SITE_URL . "/templates/" .TEMPLATEDIR . "/images/icons/resultset_last.png' />*/
    endif;


    $navi = '<div id="paging">'."";
    // start the navi

        $navi .= $first . ' '. $prev ." ";

    // loop through the numbers

    foreach (range($low, $high) as $newnumber):


           if($newnumber < 0)
		   		continue;
		   $link = ( $newnumber == 1 ) ? "1/".$firstlink :
                $newnumber."/".$baselink;
           if ($newnumber > $number):
        $navi .= '';
        elseif ($newnumber == 0):
        $navi .= '';
        else:
        $navi .= ( $newnumber == $showing ) ?
            ' <span class="active">'. $newnumber .'</span> '."" :
            ' '. quickLink ($directory."/".$link, 'Page '. $newnumber, '', $newnumber) ." ";
        endif;
    endforeach;

	$navi .= ' '. $next ." " . $last;

	if($total_records)
		$navi .= " &nbsp; &nbsp; <span class='strong'>" . $total_records . " Records Found</span> &nbsp;";

    $navi .= '</div><br/>';

	return $navi;

}

?>